<div class="container-fluid" style="margin: 0px 15px 0px 15px;">
<ol class="breadcrumb">
  <li><a href="<?php echo base_url('/index.php/inicio');?>">Início</a></li>
  <li><a href="<?php echo base_url('index.php/contatos/consulta');?>">Contato</a></li>
  <li class="active">Editar</li>
</ol>
<br/>
	<form class="form-horizontal" role="form" id="form">
		<fieldset class="cad">
			<legend>Alterar Contato/ Ramal</legend>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">Ramal</label>
					<div class="col-sm-2">
						<input type="text" id="ramal"  name="ramal" value="" class="form-control input-sm" id="" placeholder="Digite o ramal">
						<input type="hidden" id="idramal" name="idramal" value="" class="form-control input-sm" id="" />
						
					</div>
				</div>
		</fieldset>
		<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
			<thead>
				<th>Ramal</th>
				<th>Contato</th>
				<th>Cargo</th>
				<th>E-mail</th>
			</thead>
			<tbody>
			<?php
				foreach($contatos as $c){
					echo '<tr>';
					echo '<td><input type="hidden" name="contatos[]" value="'.$c->id.'">'.$c->ramal_ramal.'</td>';
					echo '<td>'.$c->nomecontato.'</td>';
					echo '<td>'.$c->cargo.'</td>';
					echo '<td>'.$c->email.'</td>';
					echo ' </tr>';
				}
			?>	  
			</tbody>
		</table>
	
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
			<?php 
				$data = array('name'=>'salvar','type' => 'submit','class' => 'btn btn-primary','content' =>'Salvar');
				echo form_button($data);
			?>
			<a id="cancelar" href="<?php echo base_url('index.php/contatos/consulta');?>" class="btn btn-default"></span>Cancelar</a>
			</div>
		</div>
	</form>
		
	

</div>
	<script src="<?php echo base_url('includes/js/jquery-cloneya.js')?>"></script>
	
	<script language="javascript" type="text/javascript">
	$(document).ready(function(){
		$( "#ramal" ).focus();
		$('#example').DataTable({
			"paging": false,
			"searching": false,
			"info": false,
			"ordering":  false
		});
		$( "#ramal" ).autocomplete({
			source: "<?php echo base_url('index.php/ramais/consultaJson');?>",
			minLength: 2,
			select: function( event, ui ) {
				$("#idramal").val(ui.item.id);
			}
		});
	
		$('#form').validate({  
			rules: {  
				ramal: { 
					required: true, 
					remote:'<?php echo base_url('index.php/ramais/validaCadRamal');?>'
				}
			},  
			messages: {  
				ramal: { required: 'Preencha o campo', remote: 'Ramal nao existe!' }
			},
			submitHandler: function( form ){  
				var dados = $( form ).serialize();  
				$.ajax({  
					type: "POST",  
					url: "<?php echo base_url('index.php/contatos/editarcontatos');?>",  
					data: dados,  
					success: function( data )  
					{  
						alertify.alert( data );
					}  
				});  
				return false;  
			} 
		}); 
	});
		
	</script>
	</body>
</html>